package com.joymart.user.repo;

import com.joymart.user.model.BusinessRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import com.joymart.common.data.jdbc.BaseRepository;
import com.joymart.user.model.User;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends BaseRepository<User, String> {
    Optional<User> findByUsername(String username);

    @Query( "select id from \"user\" where invited_by = :sourceUserId and deleted is false")
    List<String> getLowerUserIds(@Param("sourceUserId") String sourceUserId);

    boolean existsByInviteCode(String inviteCode);

    User findByInviteCode(String inviterCode);

    boolean existsByUsername(String username);

    @Query("""
        select id from \"user\" u where nickname like CONCAT('%', :keyword::text, '%') 
""")
    List<String> findIdsByNicknameContains(String keyword);


    @Query("""
        select id from \"user\" u where invited_by is null and party_a = false 
""")
    List<String> findInitialNonPartyAUsers();


}
